package model;


public class Account {
	private int balance; 
		
	public Account(int balance) {
		this.balance = balance;
	}

	public int getBalance() {
		return this.balance;
	}

	/*
	 * A negative balance is possible, but will cause 
	 * return value to be false.
	 */
	public boolean withdraw(int amount){
		if(amount < 0){
			return false;
		}
		this.balance -= amount;
		return this.balance >= 0;
	}
	public boolean deposit(int amount){
		if(amount < 0){
			return false;
		}
		this.balance += amount;
		return true;
	}
	public boolean transfer(Player otherPlayer, int amount){
		if(otherPlayer == null){
			return false;
		}
		if(!withdraw(amount)){
			return false;
		}
		if(otherPlayer.deposit(amount)){
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return "Account [balance=" + this.balance + "]";
	}
}